package com.example.uniapp01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/mdl")
public class MapController {
    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/mapSearch")
    public String mapSearch(String keyword, int distance, double latitude, double longitude) {
        String url = "https://apis.map.qq.com/ws/place/v1/search?boundary=nearby(" +
                latitude + "," + longitude + "," + distance + ")&keyword=" + keyword +
                "&page_size=5&page_index=1&key=TP7BZ-DGQLZ-Z5AX3-TC6GG-X32E3-2SBHZ";
        // 注意url里的参数顺序是有要求的，不能随意更改
        String response = restTemplate.getForObject(url, String.class);
        return response;
    }

    @GetMapping("/ipLocation")
    public String ipLocation() {
        String url = "https://apis.map.qq.com/ws/location/v1/ip?key=TP7BZ-DGQLZ-Z5AX3-TC6GG-X32E3-2SBHZ";
        String response = restTemplate.getForObject(url, String.class);
        return response;
    }
}
